package com.andy.buyu.server.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.andy.buyu.server.entity.UsrGameInfo;
import com.andy.buyu.server.entity.UsrGameLog;
import com.andy.buyu.server.game.FishGame;
import com.andy.buyu.server.game.GameConf;
import com.andy.buyu.server.game.GameUser;
import com.andy.buyu.server.game.Global;
import com.andy.buyu.server.socket.GmAction;
import com.andy.buyu.server.socket.MySocketSession;
import com.andy.buyu.server.socket.SendUtil;
import com.andy.buyu.server.socket.codec.DataWrap;
import com.andy.buyu.server.utils.CommonUtils;

/**
 * 拉霸
 * @author cuiwm
 *
 */
@Component(GmAction.ACTION_PREFIX+GmAction.ACTION_208)
public class Action208 implements IReqAction{

	private static Logger logger = LoggerFactory.getLogger(Action208.class);
	
	@Override
	public void doAction(MySocketSession session, DataWrap data) {
		GameUser user = session.getUser();
		FishGame game = user.getGame();
		if(game == null || user.getLaba() <= 0) return;
		
		UsrGameInfo gameInfo = user.getGameInfo();
		UsrGameLog log = new UsrGameLog(gameInfo);
		
		int rate = GameConf.getLabaReward(Global.sysCurrHave.get());
		log.setScriptId(999);
		log.setRate(rate);
		Integer addCoin = rate*user.getLaba();
		user.setLaba(0);
		log.setAddCoin(addCoin );
		if(addCoin > 0) {
			gameInfo.addCoin(addCoin);
			CommonUtils.saveDb(gameInfo,log);
			
			if(!user.isRobo()) {
				Global.sysCurrHave.addAndGet(-addCoin);
			}
		}
		SendUtil.send208(user,log);
		
	}


	
	
	
}
